<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.2">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"wrr123.github.io","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="talk is cheap, show me the code">
<meta property="og:type" content="website">
<meta property="og:title" content="一缕烟气">
<meta property="og:url" content="https://wrr123.github.io/page/14/index.html">
<meta property="og:site_name" content="一缕烟气">
<meta property="og:description" content="talk is cheap, show me the code">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="田园隐士">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://wrr123.github.io/page/14/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>一缕烟气</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<style>mjx-container[jax="SVG"] {
  direction: ltr;
}

mjx-container[jax="SVG"] > svg {
  overflow: visible;
}

mjx-container[jax="SVG"][display="true"] {
  display: block;
  text-align: center;
  margin: 1em 0;
}

mjx-container[jax="SVG"][justify="left"] {
  text-align: left;
}

mjx-container[jax="SVG"][justify="right"] {
  text-align: right;
}

g[data-mml-node="merror"] > g {
  fill: red;
  stroke: red;
}

g[data-mml-node="merror"] > rect[data-background] {
  fill: yellow;
  stroke: none;
}

g[data-mml-node="mtable"] > line[data-line] {
  stroke-width: 70px;
  fill: none;
}

g[data-mml-node="mtable"] > rect[data-frame] {
  stroke-width: 70px;
  fill: none;
}

g[data-mml-node="mtable"] > .mjx-dashed {
  stroke-dasharray: 140;
}

g[data-mml-node="mtable"] > .mjx-dotted {
  stroke-linecap: round;
  stroke-dasharray: 0,140;
}

g[data-mml-node="mtable"] > svg {
  overflow: visible;
}

[jax="SVG"] mjx-tool {
  display: inline-block;
  position: relative;
  width: 0;
  height: 0;
}

[jax="SVG"] mjx-tool > mjx-tip {
  position: absolute;
  top: 0;
  left: 0;
}

mjx-tool > mjx-tip {
  display: inline-block;
  padding: .2em;
  border: 1px solid #888;
  font-size: 70%;
  background-color: #F8F8F8;
  color: black;
  box-shadow: 2px 2px 5px #AAAAAA;
}

g[data-mml-node="maction"][data-toggle] {
  cursor: pointer;
}

mjx-status {
  display: block;
  position: fixed;
  left: 1em;
  bottom: 1em;
  min-width: 25%;
  padding: .2em .4em;
  border: 1px solid #888;
  font-size: 90%;
  background-color: #F8F8F8;
  color: black;
}

foreignObject[data-mjx-xml] {
  font-family: initial;
  line-height: normal;
  overflow: visible;
}

.MathJax path {
  stroke-width: 3;
}

mjx-container[display="true"] {
  overflow: auto hidden;
}

mjx-container[display="true"] + br {
  display: none;
}
</style><link rel="alternate" href="/atom.xml" title="一缕烟气" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">一缕烟气</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">沧海月明珠有泪，蓝田日暖玉生烟</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2021/03/14/http%E5%8D%8F%E8%AE%AE-how2j/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/03/14/http%E5%8D%8F%E8%AE%AE-how2j/" class="post-title-link" itemprop="url">http协议-how2j</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-14 17:50:44" itemprop="dateCreated datePublished" datetime="2021-03-14T17:50:44+08:00">2021-03-14</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>664</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="协议概念"><a href="#协议概念" class="headerlink" title="协议概念"></a>协议概念</h4><p>HTTP 超文本传输协议 Hyper Text Transfer Protocol</p>
<p>当我们在浏览器的地址栏输入一个地址的时候，就能够访问服务器的某个页面。</p>
<p>这个过程本身就是两个应用程序之间的交互，一个应用程序是浏览器，另一个应用程序是服务器。</p>
<p>协议是什么？</p>
<ul>
<li>它就是不同的应用程序之间按照事先做好的约定进行的通信。这样能互相读懂对象的意思。</li>
</ul>
<p>浏览器和WEB服务器之间，使用的就是一种叫HTTP的协议。</p>
<p>这是BS(browser server)架构模型的基础。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2021/03/14/http%E5%8D%8F%E8%AE%AE-how2j/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2021/03/14/servlet-how2j/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/03/14/servlet-how2j/" class="post-title-link" itemprop="url">servlet-how2j</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-14 16:33:08" itemprop="dateCreated datePublished" datetime="2021-03-14T16:33:08+08:00">2021-03-14</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>1.3k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h4><p>Servlet本身不能独立运行，需要在一个web应用中运行的，而一个web应用是部署在tomcat中的。</p>
<h5 id="开发一个servlet的步骤"><a href="#开发一个servlet的步骤" class="headerlink" title="开发一个servlet的步骤"></a>开发一个servlet的步骤</h5><ol>
<li>创建web应用程序</li>
<li>编写servlet代码</li>
<li>部署到tomcat中</li>
</ol>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2021/03/14/servlet-how2j/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2021/03/13/tomcat-how2j/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/03/13/tomcat-how2j/" class="post-title-link" itemprop="url">tomcat-how2j</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-13 19:09:12" itemprop="dateCreated datePublished" datetime="2021-03-13T19:09:12+08:00">2021-03-13</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>679</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h4><p>Tomcat是常见的免费的web服务器。</p>
<h5 id="Tomcat名字的由来"><a href="#Tomcat名字的由来" class="headerlink" title="Tomcat名字的由来"></a>Tomcat名字的由来</h5><p>Tomcat是野外的猫科动物，不依赖人类，独立生活。Tomcat的作者，取这个名字的初衷是希望这一款服务器可以自力更生，自给自足，像Tomcat这种野生动物一样，不依赖其他插件，而可以独立达到提供web服务的效果。</p>
<h4 id="修改端口"><a href="#修改端口" class="headerlink" title="修改端口"></a>修改端口</h4><ul>
<li>server.xml<br>tomcat的相关配置信息都在<code>server.xml</code>文件中。<h4 id="问题排查"><a href="#问题排查" class="headerlink" title="问题排查"></a>问题排查</h4></li>
<li>查看<code>JAVA_HOME</code>是否配置了</li>
<li>CATALINA_HOME未设置<br>解决：<ul>
<li>在环境变量中删除 <code>CATALINA_HOME, CATALINA_BASE</code>的配置，记得不仅要检查环境变量，还要检查用户变量。</li>
<li>或者把<code>CATALINA_HOME</code>设置为正确的tomcat目录。</li>
</ul>
</li>
<li>端口冲突</li>
<li>localhost.yyyy-mm-dd.log<ul>
<li>有可能是配置的context目录不存在</li>
<li>也有可能多了一个 <code>&gt;</code> 符号。</li>
</ul>
</li>
<li>Error FilterStart</li>
<li>JDK版本<h4 id="404问题排查"><a href="#404问题排查" class="headerlink" title="404问题排查"></a>404问题排查</h4></li>
<li>正确的端口号</li>
<li>环境变量</li>
<li>确定web应用是否成功启动</li>
<li>webapps下的ROOT目录</li>
<li>访问的地址上是否添加的web应用的名称</li>
<li>是否访问对资源了</li>
<li>不能访问WEB-INF下的资源</li>
<li>访问的资质后面多加了一个斜杠<h4 id="端口被占用"><a href="#端口被占用" class="headerlink" title="端口被占用"></a>端口被占用</h4></li>
<li>查看80端口被哪些程序占用了</li>
<li>根据pid(进程id)查询对应的应用程序</li>
<li>根据名称结束该程序<h4 id="持久化异常"><a href="#持久化异常" class="headerlink" title="持久化异常"></a>持久化异常</h4>tomcat启动的时候会报一个<code>Exception loading sessions from persistent storage</code>异常，但是又不影响正常的业务。<br>治标的解决办法：<br>只需要删除 <code>session.ser</code> 文件即可。<br>治本的解决办法：<br>关闭tomcat的持久化功能。<h4 id="部署"><a href="#部署" class="headerlink" title="部署"></a>部署</h4></li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2021/03/13/JQuery-how2j/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/03/13/JQuery-how2j/" class="post-title-link" itemprop="url">JQuery-how2j</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-13 17:57:43" itemprop="dateCreated datePublished" datetime="2021-03-13T17:57:43+08:00">2021-03-13</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>3k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>3 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h4><p>JQuery是一个javascript的框架，是对javascript的一个封装。</p>
<p>通过JQuery可以非常方便的操作HTML的元素。</p>
<p>一些常规的操作：</p>
<ul>
<li>使用JQuery隐藏和显示元素</li>
<li>理解<code>$(function(){})</code>的意义</li>
<li>通过<code>id</code>获取元素</li>
<li>增加监听器</li>
</ul>
<h4 id="常见方法"><a href="#常见方法" class="headerlink" title="常见方法"></a>常见方法</h4><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>val</td>
<td>取值</td>
</tr>
<tr>
<td>html</td>
<td>获取元素内容，如果有子元素，保留标签</td>
</tr>
<tr>
<td>text</td>
<td>获取元素内容，如果有子元素，不包含子元素标签</td>
</tr>
</tbody>
</table>
</div>
<h4 id="CSS"><a href="#CSS" class="headerlink" title="CSS"></a>CSS</h4><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>addClass</td>
<td>增加class</td>
</tr>
<tr>
<td>removeClass</td>
<td>删除class</td>
</tr>
<tr>
<td>toggleClass</td>
<td>切换class</td>
</tr>
<tr>
<td>css</td>
<td>css函数</td>
</tr>
</tbody>
</table>
</div>
<h5 id="css函数"><a href="#css函数" class="headerlink" title="css函数"></a>css函数</h5><p>格式：<code>css(property, value)</code> 或 <code>css({p1: v1, p2: v2, ...})</code></p>
<p>可以分别给元素添加单个样式或者多个样式。</p>
<h4 id="选择器"><a href="#选择器" class="headerlink" title="选择器"></a>选择器</h4><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介(*选择器)</th>
</tr>
</thead>
<tbody>
<tr>
<td>$(“tagName”)</td>
<td>元素</td>
</tr>
<tr>
<td>$(“#id”)</td>
<td>id</td>
</tr>
<tr>
<td>$(“.className”)</td>
<td>类</td>
</tr>
<tr>
<td>$(“selector1 selector2”)</td>
<td>层级</td>
</tr>
<tr>
<td>:first :last</td>
<td>最先，最后</td>
</tr>
<tr>
<td>:odd :even</td>
<td>奇偶</td>
</tr>
<tr>
<td>:hidden :visible</td>
<td>可见性</td>
</tr>
<tr>
<td>[attribute]</td>
<td>属性</td>
</tr>
<tr>
<td>:input :button …</td>
<td>表单对象</td>
</tr>
<tr>
<td>:disabled :checked :selected</td>
<td>表单对象属性</td>
</tr>
<tr>
<td>this</td>
<td>当前元素</td>
</tr>
</tbody>
</table>
</div>
<h4 id="筛选器"><a href="#筛选器" class="headerlink" title="筛选器"></a>筛选器</h4><p>筛选器指的是在已经通过 <strong>选择器</strong> 选中了元素后，在此基础上进一步选择。</p>
<div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>first()</td>
<td>第一个</td>
</tr>
<tr>
<td>last()</td>
<td>最后一个</td>
</tr>
<tr>
<td>eq(num)</td>
<td>第 num 个</td>
</tr>
<tr>
<td>parent()</td>
<td>父元素</td>
</tr>
<tr>
<td>parents()</td>
<td>祖先元素</td>
</tr>
<tr>
<td>children()</td>
<td>儿子</td>
</tr>
<tr>
<td>find()</td>
<td>后代元素</td>
</tr>
<tr>
<td>siblings()</td>
<td>同级</td>
</tr>
</tbody>
</table>
</div>
<h4 id="属性"><a href="#属性" class="headerlink" title="属性"></a>属性</h4><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>attr</td>
<td>获取</td>
</tr>
<tr>
<td>attr(属性， 值)</td>
<td>修改</td>
</tr>
<tr>
<td>removeAttr</td>
<td>删除</td>
</tr>
</tbody>
</table>
</div>
<h5 id="attr和prop的区别"><a href="#attr和prop的区别" class="headerlink" title="attr和prop的区别"></a>attr和prop的区别</h5><ul>
<li>对于自定义属性，attr可以获取，但是prop不能获取</li>
<li>对于选中属性<ul>
<li>attr只能获取初始值，无论是否改变</li>
<li>prop能够访问变化后的值，并且以<code>true | false</code>的布尔型返回</li>
</ul>
</li>
</ul>
<h4 id="效果"><a href="#效果" class="headerlink" title="效果"></a>效果</h4><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>show hide toggle</td>
<td>显示 隐藏 切换</td>
</tr>
<tr>
<td>slideUp slideDown slideToggle</td>
<td>向上滑动 向下滑动 滑动切换</td>
</tr>
<tr>
<td>fadeIn fadeOut fadeToggle fadeTo</td>
<td>淡入 淡出 淡入淡出切换 指定淡入程度</td>
</tr>
<tr>
<td>animate</td>
<td>自定义动画效果</td>
</tr>
<tr>
<td>callback</td>
<td>回调函数</td>
</tr>
</tbody>
</table>
</div>
<h4 id="事件"><a href="#事件" class="headerlink" title="事件"></a>事件</h4><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>$(docuemnt).ready()</code>  <code>$()</code> load()</td>
<td>加载</td>
</tr>
<tr>
<td>click() dblclick()</td>
<td>单击 双击</td>
</tr>
<tr>
<td>keydown() keypress() keyup()</td>
<td>键盘事件</td>
</tr>
<tr>
<td>mousedown() mouseup() mousemove() …</td>
<td>鼠标事件</td>
</tr>
<tr>
<td>focus() blur()</td>
<td>焦点移入、移出事件</td>
</tr>
<tr>
<td>change()</td>
<td>改变</td>
</tr>
<tr>
<td>submit()</td>
<td>提交</td>
</tr>
<tr>
<td>on()</td>
<td>绑定</td>
</tr>
<tr>
<td>trigger()</td>
<td>触发事件</td>
</tr>
</tbody>
</table>
</div>
<h4 id="Ajax"><a href="#Ajax" class="headerlink" title="Ajax"></a>Ajax</h4><p>JQuery对Ajax的支持，使得其对Ajax的操作简化了很多。</p>
<div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>$.ajax()</td>
<td>提交ajax请求</td>
</tr>
<tr>
<td>$.get()</td>
<td>使用get方式提交ajax</td>
</tr>
<tr>
<td>$.post()</td>
<td>使用post方式提交ajax</td>
</tr>
<tr>
<td>load()</td>
<td>最简单的调用ajax的方式</td>
</tr>
<tr>
<td>sirialize()</td>
<td>格式化form下的输入数据</td>
</tr>
</tbody>
</table>
</div>
<p><strong>有时候form下的输入内容比较多，一个一个的取比较麻烦，就可以用<code>serialize()</code>把输入数据格式化成字符串。</strong></p>
<h4 id="数组操作"><a href="#数组操作" class="headerlink" title="数组操作"></a>数组操作</h4><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>$.each()</td>
<td>遍历</td>
</tr>
<tr>
<td>$.unique()</td>
<td>去除重复</td>
</tr>
<tr>
<td>$.inArray()</td>
<td>检查数组中是否含有某个元素</td>
</tr>
</tbody>
</table>
</div>
<h4 id="字符串操作"><a href="#字符串操作" class="headerlink" title="字符串操作"></a>字符串操作</h4><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>$.trim()</td>
<td>去除首尾空白</td>
</tr>
</tbody>
</table>
</div>
<h4 id="JSON"><a href="#JSON" class="headerlink" title="JSON"></a>JSON</h4><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>$.parseJSON()</td>
<td>将json格式的字符串，转换为JSON对象</td>
</tr>
</tbody>
</table>
</div>
<p>一个栗子：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">&lt;script src=<span class="string">"https://how2j.cn/study/jquery.min.js"</span>&gt;&lt;/script&gt;</span><br><span class="line">    </span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">  </span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">var</span> s1 = <span class="string">"{\"name\":\"盖伦\""</span>;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">var</span> s2 = <span class="string">",\"hp\":616}"</span>;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">var</span> s3 = s1+s2;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">  </span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"这是一个JSON格式的字符串:"</span> + s3);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"&lt;br&gt;"</span>);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">var</span> gareen = $.<span class="title function_">parseJSON</span>(s3);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">  </span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"这是一个JSON对象: "</span> + gareen);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">   </span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></span><br></pre></td></tr></table></figure>
<h4 id="对象转换"><a href="#对象转换" class="headerlink" title="对象转换"></a>对象转换</h4><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>get(0)  [0]</td>
<td>JQuery转DOM</td>
</tr>
<tr>
<td>$()</td>
<td>DOM转JQuery</td>
</tr>
</tbody>
</table>
</div>
<p>一个栗子:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">&lt;script src=<span class="string">"https://how2j.cn/study/jquery.min.js"</span>&gt;&lt;/script&gt;</span><br><span class="line">    </span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">$(<span class="keyword">function</span>(<span class="params"></span>){</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">   $(<span class="string">"#b1"</span>).<span class="title function_">click</span>(<span class="keyword">function</span>(<span class="params"></span>){</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">      <span class="keyword">var</span> div= $(<span class="string">"#d"</span>);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">      <span class="keyword">var</span> d = div[<span class="number">0</span>];</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">      <span class="keyword">var</span> s =<span class="string">"JQuery对象是 "</span> + div;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">      s +=<span class="string">"\n对应的DOM对象是 "</span> + d</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">      <span class="title function_">alert</span>(s);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">   });</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">});</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">     </span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></span><br><span class="line">  <span class="language-xml"><span class="tag">&lt;<span class="name">button</span> <span class="attr">id</span>=<span class="string">"b1"</span>&gt;</span>JQuery对象div转为DOM对象d<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span></span><br><span class="line">&lt;br&gt;</span><br><span class="line">&lt;br&gt;</span><br><span class="line">    </span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">style</span>&gt;</span><span class="language-css"></span></span></span><br><span class="line"><span class="language-css"><span class="language-xml"><span class="selector-class">.pink</span>{</span></span></span><br><span class="line"><span class="language-css"><span class="language-xml">   <span class="attribute">background-color</span>:pink;</span></span></span><br><span class="line"><span class="language-css"><span class="language-xml">}</span></span></span><br><span class="line"><span class="language-css"><span class="language-xml"></span><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span></span><br><span class="line">     </span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"d"</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">Hello JQuery</span></span><br><span class="line"><span class="language-xml"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br></pre></td></tr></table></figure>
<p>另一个栗子：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">&lt;script src=<span class="string">"https://how2j.cn/study/jquery.min.js"</span>&gt;&lt;/script&gt;</span><br><span class="line">    </span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">$(<span class="keyword">function</span>(<span class="params"></span>){</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">   $(<span class="string">"#b1"</span>).<span class="title function_">click</span>(<span class="keyword">function</span>(<span class="params"></span>){</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">      <span class="keyword">var</span> div= <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">"d"</span>);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">      <span class="keyword">var</span> d = $(div);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">      <span class="keyword">var</span> s =<span class="string">"DOM对象是 "</span> + div;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">      s +=<span class="string">"\n对应的JQuery对象是 "</span> + d</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">      <span class="title function_">alert</span>(s);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">   });</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">});</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">     </span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></span><br><span class="line">  <span class="language-xml"><span class="tag">&lt;<span class="name">button</span> <span class="attr">id</span>=<span class="string">"b1"</span>&gt;</span>DOM对象div转为JQuery对象d<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span></span><br><span class="line">&lt;br&gt;</span><br><span class="line">&lt;br&gt;</span><br><span class="line">    </span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">style</span>&gt;</span><span class="language-css"></span></span></span><br><span class="line"><span class="language-css"><span class="language-xml"><span class="selector-class">.pink</span>{</span></span></span><br><span class="line"><span class="language-css"><span class="language-xml">   <span class="attribute">background-color</span>:pink;</span></span></span><br><span class="line"><span class="language-css"><span class="language-xml">}</span></span></span><br><span class="line"><span class="language-css"><span class="language-xml"></span><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span></span><br><span class="line">     </span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"d"</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">Hello JQuery</span></span><br><span class="line"><span class="language-xml"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2021/03/12/%E5%89%8D%E7%AB%AF%E9%83%A8%E5%88%86-how2j/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/03/12/%E5%89%8D%E7%AB%AF%E9%83%A8%E5%88%86-how2j/" class="post-title-link" itemprop="url">前端部分-how2j</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-12 13:32:44" itemprop="dateCreated datePublished" datetime="2021-03-12T13:32:44+08:00">2021-03-12</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>3.1k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>3 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="HTML"><a href="#HTML" class="headerlink" title="HTML"></a>HTML</h4><h5 id="中文问题"><a href="#中文问题" class="headerlink" title="中文问题"></a>中文问题</h5><p>可以在浏览器上设置编码方式为<code>GB2312</code>，或者在html的最前面加上编码</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">"Content-Type"</span> <span class="attr">content</span>=<span class="string">"text/html;charset=GB2312"</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h5 id="元素"><a href="#元素" class="headerlink" title="元素"></a>元素</h5><ul>
<li><p>完整的HTML</p>
<p>一个完整的html文件应该至少包含html元素，body元素，以及里面的内容。</p>
</li>
<li><p>不完整的元素</p>
</li>
<li><p>有的特殊元素</p>
<p>有的特殊元素，没有内容，即开始和结束标签直接放在一起。</p>
<p>比如hr, br等等。</p>
</li>
</ul>
<h6 id="属性"><a href="#属性" class="headerlink" title="属性"></a>属性</h6><p>属性是用来修饰标签的。</p>
<h6 id="注释"><a href="#注释" class="headerlink" title="注释"></a>注释</h6><p>html用<code>&lt;!-- --&gt;</code>来进行注释。</p>
<h5 id="基本元素"><a href="#基本元素" class="headerlink" title="基本元素"></a>基本元素</h5><div class="table-container">
<table>
<thead>
<tr>
<th>格式</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&lt;h1&gt; 到 &lt;h6&gt;</code></td>
<td>分别表示不同大小的标题</td>
</tr>
<tr>
<td><code>&lt;p&gt;</code></td>
<td>段落，自带换行</td>
</tr>
<tr>
<td><code>&lt;b&gt; 或 &lt;strong&gt;</code></td>
<td>粗体</td>
</tr>
<tr>
<td><code>&lt;i&gt; 或 &lt;em&gt;</code></td>
<td>斜体</td>
</tr>
<tr>
<td><code>&lt;pre&gt;</code></td>
<td>在网页上显示代码，如java代码等</td>
</tr>
<tr>
<td><code>&lt;del&gt;</code></td>
<td>删除线效果</td>
</tr>
<tr>
<td><code>&lt;ins&gt;</code></td>
<td>下划线，其中<u>标签也可以实现下划线效果，但是不建议使用</u></td>
</tr>
<tr>
<td><code>&lt;img&gt;</code></td>
<td>图像</td>
</tr>
<tr>
<td><code>&lt;a&gt;</code></td>
<td>超链接</td>
</tr>
<tr>
<td><code>&lt;table&gt;，&lt;tr&gt;, &lt;td&gt;</code></td>
<td>表格, 行， 单元格</td>
</tr>
<tr>
<td><code>&lt;ul&gt;, &lt;ol&gt;</code></td>
<td>无序列表， 有序列表</td>
</tr>
<tr>
<td><code>&lt;div&gt;, &lt;span&gt;</code></td>
<td>块级元素， 内联元素，它们通常结合CSS来进行页面布局</td>
</tr>
</tbody>
</table>
</div>
<h5 id="字体"><a href="#字体" class="headerlink" title="字体"></a>字体</h5><h6 id="字体元素"><a href="#字体元素" class="headerlink" title="字体元素"></a>字体元素</h6><p>font常用的属性有color和size，分别表示颜色和大小。</p>
<h6 id="颜色表示法"><a href="#颜色表示法" class="headerlink" title="颜色表示法"></a>颜色表示法</h6><ul>
<li>颜色名，如<code>red, blue</code></li>
<li>颜色对应的16进制，如<code>#ff0000</code>就表示红色。</li>
</ul>
<h5 id="内联框架"><a href="#内联框架" class="headerlink" title="内联框架"></a>内联框架</h5><p><code>&lt;iframe&gt;</code>即内联框架，通过内联框架可以实现在网页中<code>插入</code>网页。</p>
<h6 id="表单元素"><a href="#表单元素" class="headerlink" title="表单元素"></a>表单元素</h6><div class="table-container">
<table>
<thead>
<tr>
<th>格式</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&lt;input type="text"&gt;</code></td>
<td>文本框</td>
</tr>
<tr>
<td><code>&lt;input type="password"&gt;</code></td>
<td>密码框</td>
</tr>
<tr>
<td><code>&lt;form&gt;</code></td>
<td>表单</td>
</tr>
<tr>
<td><code>&lt;input type="radio"&gt;</code></td>
<td>单选框</td>
</tr>
<tr>
<td><code>&lt;input type="checked"&gt;</code></td>
<td>复选框</td>
</tr>
<tr>
<td><code>&lt;select&gt; &lt;option&gt;</code></td>
<td>下拉列表</td>
</tr>
<tr>
<td><code>&lt;textarea&gt;</code></td>
<td>文本域</td>
</tr>
<tr>
<td><code>&lt;input type="button"&gt;</code></td>
<td>普通按钮</td>
</tr>
<tr>
<td><code>&lt;input type="submit"&gt;</code></td>
<td>提交按钮</td>
</tr>
<tr>
<td><code>&lt;input type="reset"&gt;</code></td>
<td>重置按钮</td>
</tr>
<tr>
<td><code>&lt;input type="image"&gt;</code></td>
<td>使用图像作为按钮进行form的提交</td>
</tr>
<tr>
<td><code>&lt;button&gt;</code></td>
<td>按钮标签</td>
</tr>
</tbody>
</table>
</div>
<h4 id="CSS"><a href="#CSS" class="headerlink" title="CSS"></a>CSS</h4><h5 id="css语法"><a href="#css语法" class="headerlink" title="css语法"></a>css语法</h5><p><code>selector {property: value}</code>,即</p>
<p>选择器 {属性: 值}。</p>
<h5 id="css选择器"><a href="#css选择器" class="headerlink" title="css选择器"></a>css选择器</h5><ul>
<li><p>元素选择器</p>
</li>
<li><p>id选择器</p>
</li>
<li><p>类选择器</p>
</li>
<li><p>更准确的选择(同时根据元素名和class来选择)</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">p</span><span class="selector-class">.blue</span>{</span><br><span class="line">  <span class="attribute">color</span>:blue;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h5 id="注释-1"><a href="#注释-1" class="headerlink" title="注释"></a>注释</h5><p>以<code>/*</code> 开始，以<code>*/</code>结束。</p>
<h5 id="常用的CSS属性"><a href="#常用的CSS属性" class="headerlink" title="常用的CSS属性"></a>常用的CSS属性</h5><div class="table-container">
<table>
<thead>
<tr>
<th>属性</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>width, height</td>
<td>尺寸大小，元素的宽度和高度</td>
</tr>
<tr>
<td>background-*（color，image）</td>
<td>背景（颜色，图片）</td>
</tr>
<tr>
<td>color</td>
<td>文字颜色</td>
</tr>
<tr>
<td>text-align</td>
<td>对齐</td>
</tr>
<tr>
<td>text-decoration</td>
<td>文本修饰</td>
</tr>
<tr>
<td>line-height</td>
<td>行间距</td>
</tr>
<tr>
<td>letter-spacing</td>
<td>字符间距</td>
</tr>
<tr>
<td>word-spacing</td>
<td>单词间距</td>
</tr>
<tr>
<td>text-index</td>
<td>首行缩进</td>
</tr>
<tr>
<td>text-transform</td>
<td>大小写</td>
</tr>
<tr>
<td>white-space</td>
<td>空白格</td>
</tr>
<tr>
<td>font-size</td>
<td>尺寸</td>
</tr>
<tr>
<td>font-style</td>
<td>风格</td>
</tr>
<tr>
<td>font-weight</td>
<td>粗细</td>
</tr>
<tr>
<td>font-family</td>
<td>字库</td>
</tr>
<tr>
<td>cursor</td>
<td>鼠标样式</td>
</tr>
<tr>
<td>table-layout</td>
<td>表格布局</td>
</tr>
<tr>
<td>border-collapse</td>
<td>表格边框</td>
</tr>
<tr>
<td>border-style</td>
<td>边框风格</td>
</tr>
<tr>
<td>border-color</td>
<td>边框颜色</td>
</tr>
<tr>
<td>border-width</td>
<td>边框宽度</td>
</tr>
<tr>
<td>padding</td>
<td>内边距，指元素的内容和边框之间的距离</td>
</tr>
<tr>
<td>margin</td>
<td>外边距，指元素边框和元素边框之间的距离</td>
</tr>
</tbody>
</table>
</div>
<h5 id="css优先级问题"><a href="#css优先级问题" class="headerlink" title="css优先级问题"></a>css优先级问题</h5><ol>
<li><code>!important</code></li>
<li>style属性</li>
<li>style标签</li>
<li>外部css文件</li>
</ol>
<h5 id="布局"><a href="#布局" class="headerlink" title="布局"></a>布局</h5><ul>
<li><p>绝对定位 <code>position: absolute;</code></p>
</li>
<li><p>相对定位 <code>position: relative;</code></p>
</li>
<li><p>浮动 <code>float:left/right;</code></p>
<p>清楚浮动带来的影响，使用 <code>clear</code>.</p>
</li>
</ul>
<h4 id="JavaScript"><a href="#JavaScript" class="headerlink" title="JavaScript"></a>JavaScript</h4><h5 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h5><p>JavaScript用于网页与用户之间的交互，完整的JavaScript由语言基础、BOM和DOM组成。</p>
<h5 id="script标签"><a href="#script标签" class="headerlink" title="script标签"></a>script标签</h5><p>JavaScript代码必须放在script标签中，script标签可以放在html的任何地方，一般建议放在head标签里。</p>
<h5 id="调试方法"><a href="#调试方法" class="headerlink" title="调试方法"></a>调试方法</h5><ul>
<li>alert调试</li>
<li>使用浏览器自带的调试功能</li>
<li>console.log()调试</li>
</ul>
<h5 id="基本数据类型"><a href="#基本数据类型" class="headerlink" title="基本数据类型"></a>基本数据类型</h5><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>undefined</td>
<td>声明了但未赋值</td>
</tr>
<tr>
<td>Boolean</td>
<td>布尔</td>
</tr>
<tr>
<td>Number</td>
<td>数字</td>
</tr>
<tr>
<td>String</td>
<td>字符串</td>
</tr>
<tr>
<td>var</td>
<td>动态类型</td>
</tr>
<tr>
<td>typeof</td>
<td>变量类型判断</td>
</tr>
<tr>
<td>null</td>
<td>空对象、或对象不存在</td>
</tr>
</tbody>
</table>
</div>
<h5 id="作用域"><a href="#作用域" class="headerlink" title="作用域"></a>作用域</h5><ul>
<li>全局变量</li>
<li>局部变量</li>
</ul>
<h5 id="事件"><a href="#事件" class="headerlink" title="事件"></a>事件</h5><p>事件有很多种，比如鼠标移动、鼠标点击和键盘点击等等。</p>
<h5 id="错误处理"><a href="#错误处理" class="headerlink" title="错误处理"></a>错误处理</h5><p>JavaScript提供了一种try catch的错误处理机制，当有错误抛出的时候，可以catch住。</p>
<h5 id="对象"><a href="#对象" class="headerlink" title="对象"></a>对象</h5><ul>
<li>数字 Number</li>
<li>字符串 String</li>
<li>数组 Array</li>
<li>日期 Date</li>
<li>Math</li>
<li>自定义对象</li>
</ul>
<h5 id="BOM"><a href="#BOM" class="headerlink" title="BOM"></a>BOM</h5><p>浏览器对象模型（Browser Object Model）</p>
<ul>
<li>Window 窗口</li>
<li>Navigator 浏览器</li>
<li>Screen 客户端屏幕</li>
<li>History 访问历史</li>
<li>Location 浏览器地址</li>
</ul>
<h6 id="定时器"><a href="#定时器" class="headerlink" title="定时器"></a>定时器</h6><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>setTimeout</td>
<td>只执行一次</td>
</tr>
<tr>
<td>setInterval</td>
<td>不停的重复执行</td>
</tr>
<tr>
<td>clearInterval</td>
<td>终止重复执行</td>
</tr>
</tbody>
</table>
</div>
<p><strong>不要在setInterval调用的函数中使用<code>document.write();</code></strong></p>
<h4 id="JSON"><a href="#JSON" class="headerlink" title="JSON"></a>JSON</h4><p>JSON JavaScript对象表示法（Java Script Object Notation）是一种存储数据的方式。</p>
<h5 id="对象转换"><a href="#对象转换" class="headerlink" title="对象转换"></a>对象转换</h5><ul>
<li><p>将字符串转换为JSON对象</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">var</span> s1 = <span class="string">"{\"name\":\"盖伦\""</span>;</span><br><span class="line"><span class="keyword">var</span> s2 = <span class="string">",\"hp\":616}"</span>;</span><br><span class="line"><span class="keyword">var</span> s3 = s1+s2;</span><br><span class="line"> </span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"这是一个JSON格式的字符串:"</span> + s3);</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"&lt;br&gt;"</span>);</span><br><span class="line"><span class="keyword">var</span> gareen = <span class="built_in">eval</span>(<span class="string">"("</span>+s3+<span class="string">")"</span>);</span><br><span class="line"> </span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"这是一个JSON对象: "</span> + gareen);</span><br><span class="line">  </span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>JSON对象转换为字符串</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line"><span class="keyword">var</span> hero = {<span class="string">"name"</span>:<span class="string">"盖伦"</span>,<span class="string">"hp"</span>:<span class="string">"616"</span>};</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"这是一个json 对象："</span>+ hero);</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"&lt;br&gt;"</span>);</span><br><span class="line"><span class="keyword">var</span> heroString = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(hero)</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"这是一个json 字符串："</span>+ heroString );</span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure>
</li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2021/03/11/java%E4%B8%AD%E7%BA%A7-how2j/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/03/11/java%E4%B8%AD%E7%BA%A7-how2j/" class="post-title-link" itemprop="url">java中级-how2j</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-11 16:30:13" itemprop="dateCreated datePublished" datetime="2021-03-11T16:30:13+08:00">2021-03-11</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>5.9k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>5 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="异常处理"><a href="#异常处理" class="headerlink" title="异常处理"></a>异常处理</h4><h5 id="什么叫异常"><a href="#什么叫异常" class="headerlink" title="什么叫异常"></a>什么叫异常</h5><p>定义：导致程序的正常流程被中断的事件，叫做异常。</p>
<h6 id="如文件不存在异常"><a href="#如文件不存在异常" class="headerlink" title="如文件不存在异常"></a>如文件不存在异常</h6><p>一个栗子：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> exception;</span><br><span class="line">  </span><br><span class="line"><span class="keyword">import</span> java.io.File;</span><br><span class="line"><span class="keyword">import</span> java.io.FileInputStream;</span><br><span class="line">  </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestException</span> {</span><br><span class="line">  </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">          </span><br><span class="line">        File f= <span class="keyword">new</span> <span class="title class_">File</span>(<span class="string">"d:/LOL.exe"</span>);</span><br><span class="line">          </span><br><span class="line">        <span class="comment">//试图打开文件LOL.exe，会抛出FileNotFoundException，如果不处理该异常，就会有编译错误</span></span><br><span class="line">        <span class="keyword">new</span> <span class="title class_">FileInputStream</span>(f);</span><br><span class="line">          </span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h5 id="异常处理-1"><a href="#异常处理-1" class="headerlink" title="异常处理"></a>异常处理</h5><p><code>try catch finally throws</code></p>
<h6 id="thorw和throws的区别"><a href="#thorw和throws的区别" class="headerlink" title="thorw和throws的区别"></a><code>thorw</code>和<code>throws</code>的区别</h6><ul>
<li>throws出现在方法声明上，而throws通常出现在方法体内</li>
<li>throws表示出现异常的一种可能性，并不一定会发生这些异常；而throw则是抛出了异常，执行throw则一定抛出了某个异常对象。</li>
</ul>
<h5 id="异常分类"><a href="#异常分类" class="headerlink" title="异常分类"></a>异常分类</h5><ul>
<li>可查异常</li>
<li>运行时异常</li>
<li>错误</li>
</ul>
<p>其中运行时异常和错误也称为非可查异常。</p>
<h5 id="Throwable"><a href="#Throwable" class="headerlink" title="Throwable"></a>Throwable</h5><p>Throwable是类，Exception和Error都继承了该类。</p>
<h5 id="自定义异常"><a href="#自定义异常" class="headerlink" title="自定义异常"></a>自定义异常</h5><h4 id="I-O"><a href="#I-O" class="headerlink" title="I/O"></a>I/O</h4><h5 id="文件对象"><a href="#文件对象" class="headerlink" title="文件对象"></a>文件对象</h5><p>使用绝对路径或相对路径创建File对象。</p>
<h5 id="什么是流"><a href="#什么是流" class="headerlink" title="什么是流"></a>什么是流</h5><p>流就是一系列的数据。</p>
<h5 id="字节流"><a href="#字节流" class="headerlink" title="字节流"></a>字节流</h5><h6 id="ASCII码"><a href="#ASCII码" class="headerlink" title="ASCII码"></a>ASCII码</h6><p>所有的数据在计算机中都是以数字的形式存放的。</p>
<h5 id="关闭流的方式"><a href="#关闭流的方式" class="headerlink" title="关闭流的方式"></a>关闭流的方式</h5><p>所有的流，无论是输入流还是输出流，使用完毕之后，都应该关闭。如果不关闭，会产生对资源占用的浪费。当量比较大的时候，会影响到业务的正常开展。</p>
<ul>
<li>在try中关闭</li>
<li>在finally中关闭</li>
<li>使用try()的方式 【推荐】</li>
</ul>
<h5 id="字符流"><a href="#字符流" class="headerlink" title="字符流"></a>字符流</h5><p>Reader字符输入流，Writer字符输出流，专门用于字符的形式读取和写入数据。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> stream;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">import</span> java.io.File;</span><br><span class="line"><span class="keyword">import</span> java.io.FileReader;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestStream</span> {</span><br><span class="line"> </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">        <span class="comment">// 准备文件lol.txt其中的内容是AB</span></span><br><span class="line">        <span class="type">File</span> <span class="variable">f</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(<span class="string">"d:/lol.txt"</span>);</span><br><span class="line">        <span class="comment">// 创建基于文件的Reader</span></span><br><span class="line">        <span class="keyword">try</span> (<span class="type">FileReader</span> <span class="variable">fr</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">FileReader</span>(f)) {</span><br><span class="line">            <span class="comment">// 创建字符数组，其长度就是文件的长度</span></span><br><span class="line">            <span class="type">char</span>[] all = <span class="keyword">new</span> <span class="title class_">char</span>[(<span class="type">int</span>) f.length()];</span><br><span class="line">            <span class="comment">// 以字符流的形式读取文件所有内容</span></span><br><span class="line">            fr.read(all);</span><br><span class="line">            <span class="keyword">for</span> (<span class="type">char</span> b : all) {</span><br><span class="line">                <span class="comment">// 打印出来是A B</span></span><br><span class="line">                System.out.println(b);</span><br><span class="line">            }</span><br><span class="line">        } <span class="keyword">catch</span> (IOException e) {</span><br><span class="line">            <span class="comment">// TODO Auto-generated catch block</span></span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        }</span><br><span class="line"> </span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h5 id="中文问题"><a href="#中文问题" class="headerlink" title="中文问题"></a>中文问题</h5><h6 id="常见编码"><a href="#常见编码" class="headerlink" title="常见编码"></a>常见编码</h6><blockquote>
<p>工作后经常接触的编码方式有如下几种：<br><strong>ISO-8859-1 ASCII</strong> 数字和西欧字母<br><strong>GBK GB2312 BIG5</strong> 中文<br><strong>UNICODE</strong> (统一码，万国码)</p>
<p>其中<br>ISO-8859-1 包含 ASCII<br>GB2312 是简体中文，BIG5是繁体中文，GBK同时包含简体和繁体以及日文。<br>UNICODE 包括了所有的文字，无论中文，英文，藏文，法文，世界所有的文字都包含其中</p>
</blockquote>
<h5 id="缓存流"><a href="#缓存流" class="headerlink" title="缓存流"></a>缓存流</h5><p>缓存流在写入数据的时候，会先把数据写入到缓存区，直到缓存区达到一定的量，才把这些数据，一起写入到硬盘中去。按照这种操作模式，就不会像字节流、字符流那样每写一个字节都访问硬盘，从而减少了IO操作。</p>
<h6 id="flush"><a href="#flush" class="headerlink" title="flush"></a>flush</h6><p>有的时候，需要立即把数据写入到硬盘中，而不是等缓存满了才写出去。这时候就需要用到<code>flush</code>。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> stream;</span><br><span class="line">    </span><br><span class="line"><span class="keyword">import</span> java.io.File;</span><br><span class="line"><span class="keyword">import</span> java.io.FileWriter;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.io.PrintWriter;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestStream</span> {</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">        <span class="comment">//向文件lol2.txt中写入三行语句</span></span><br><span class="line">        <span class="type">File</span> <span class="variable">f</span> <span class="operator">=</span><span class="keyword">new</span> <span class="title class_">File</span>(<span class="string">"d:/lol2.txt"</span>);</span><br><span class="line">        <span class="comment">//创建文件字符流</span></span><br><span class="line">        <span class="comment">//缓存流必须建立在一个存在的流的基础上</span></span><br><span class="line">        <span class="keyword">try</span>(<span class="type">FileWriter</span> <span class="variable">fr</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">FileWriter</span>(f);<span class="type">PrintWriter</span> <span class="variable">pw</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">PrintWriter</span>(fr);) {</span><br><span class="line">            pw.println(<span class="string">"garen kill teemo"</span>);</span><br><span class="line">            <span class="comment">//强制把缓存中的数据写入硬盘，无论缓存是否已满</span></span><br><span class="line">                pw.flush();           </span><br><span class="line">            pw.println(<span class="string">"teemo revive after 1 minutes"</span>);</span><br><span class="line">                pw.flush();</span><br><span class="line">            pw.println(<span class="string">"teemo try to garen, but killed again"</span>);</span><br><span class="line">                pw.flush();</span><br><span class="line">        } <span class="keyword">catch</span> (IOException e) {</span><br><span class="line">            <span class="comment">// TODO Auto-generated catch block</span></span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        }</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h5 id="数据流"><a href="#数据流" class="headerlink" title="数据流"></a>数据流</h5><ul>
<li><code>DataInputStream</code> 数据输入流</li>
<li><code>DataOutputStream</code> 数据输出流</li>
</ul>
<h5 id="对象流"><a href="#对象流" class="headerlink" title="对象流"></a>对象流</h5><p>对象流指的是可以直接把一个以流的形式传输给其他的介质，比如硬盘。</p>
<p>一个对象以流的形式进行传输，叫做序列化。</p>
<p>该对象所对应的类，必须是实现<code>Serializable</code>接口。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> stream;</span><br><span class="line">    </span><br><span class="line"><span class="keyword">import</span> java.io.File;</span><br><span class="line"><span class="keyword">import</span> java.io.FileInputStream;</span><br><span class="line"><span class="keyword">import</span> java.io.FileOutputStream;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.io.ObjectInputStream;</span><br><span class="line"><span class="keyword">import</span> java.io.ObjectOutputStream;</span><br><span class="line">  </span><br><span class="line"><span class="keyword">import</span> charactor.Hero;</span><br><span class="line">    </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestStream</span> {</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">        <span class="comment">//创建一个Hero garen</span></span><br><span class="line">        <span class="comment">//要把Hero对象直接保存在文件上，务必让Hero类实现Serializable接口</span></span><br><span class="line">        <span class="type">Hero</span> <span class="variable">h</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Hero</span>();</span><br><span class="line">        h.name = <span class="string">"garen"</span>;</span><br><span class="line">        h.hp = <span class="number">616</span>;</span><br><span class="line">          </span><br><span class="line">        <span class="comment">//准备一个文件用于保存该对象</span></span><br><span class="line">        <span class="type">File</span> <span class="variable">f</span> <span class="operator">=</span><span class="keyword">new</span> <span class="title class_">File</span>(<span class="string">"d:/garen.lol"</span>);</span><br><span class="line"> </span><br><span class="line">        <span class="keyword">try</span>(</span><br><span class="line">            <span class="comment">//创建对象输出流</span></span><br><span class="line">            <span class="type">FileOutputStream</span> <span class="variable">fos</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">FileOutputStream</span>(f);</span><br><span class="line">            <span class="type">ObjectOutputStream</span> <span class="variable">oos</span> <span class="operator">=</span><span class="keyword">new</span> <span class="title class_">ObjectOutputStream</span>(fos);</span><br><span class="line">            <span class="comment">//创建对象输入流              </span></span><br><span class="line">            <span class="type">FileInputStream</span> <span class="variable">fis</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">FileInputStream</span>(f);</span><br><span class="line">            <span class="type">ObjectInputStream</span> <span class="variable">ois</span> <span class="operator">=</span><span class="keyword">new</span> <span class="title class_">ObjectInputStream</span>(fis);</span><br><span class="line">        ) {</span><br><span class="line">            oos.writeObject(h);</span><br><span class="line">            <span class="type">Hero</span> <span class="variable">h2</span> <span class="operator">=</span> (Hero) ois.readObject();</span><br><span class="line">            System.out.println(h2.name);</span><br><span class="line">            System.out.println(h2.hp);</span><br><span class="line">               </span><br><span class="line">        } <span class="keyword">catch</span> (IOException e) {</span><br><span class="line">            <span class="comment">// TODO Auto-generated catch block</span></span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        } <span class="keyword">catch</span> (ClassNotFoundException e) {</span><br><span class="line">            <span class="comment">// TODO Auto-generated catch block</span></span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        }</span><br><span class="line">            </span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h5 id="流关系图"><a href="#流关系图" class="headerlink" title="流关系图"></a>流关系图</h5><p><img src="http://localhost:4000/2021/03/11/java%E4%B8%AD%E7%BA%A7-how2j/002.png" alt></p>
<h4 id="集合框架"><a href="#集合框架" class="headerlink" title="集合框架"></a>集合框架</h4><h5 id="ArrayList"><a href="#ArrayList" class="headerlink" title="ArrayList"></a>ArrayList</h5><h6 id="与数组的区别"><a href="#与数组的区别" class="headerlink" title="与数组的区别"></a>与数组的区别</h6><ul>
<li><p>数组的局限性</p>
</li>
<li><p>ArrayList存放对象</p>
<p>引入了容器的概念。容器的容量<code>capacity</code>会随着对象的增加，自动增长。常见的容器有<code>ArrayList</code>等。</p>
</li>
</ul>
<h6 id="常用方法"><a href="#常用方法" class="headerlink" title="常用方法"></a>常用方法</h6><div class="table-container">
<table>
<thead>
<tr>
<th>方法名</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>add</td>
<td>增加</td>
</tr>
<tr>
<td>contains</td>
<td>判断是否存在</td>
</tr>
<tr>
<td>get</td>
<td>获取指定位置的对象</td>
</tr>
<tr>
<td>indexOf</td>
<td>获取对象所处的位置</td>
</tr>
<tr>
<td>remove</td>
<td>删除</td>
</tr>
<tr>
<td>size</td>
<td>获取大小</td>
</tr>
<tr>
<td>toArray</td>
<td>转换为数组</td>
</tr>
<tr>
<td>addAll</td>
<td>把另一个容器的所有对象加进来</td>
</tr>
<tr>
<td>clear</td>
<td>清空</td>
</tr>
</tbody>
</table>
</div>
<p><strong>Q1: 在ArrayList的for循环遍历中，是不能删除数据的。那么，如何删除数据呢？</strong></p>
<ul>
<li>使用迭代器遍历，<code>Iterator</code></li>
</ul>
<h6 id="List接口"><a href="#List接口" class="headerlink" title="List接口"></a>List接口</h6><h6 id="泛型Generic"><a href="#泛型Generic" class="headerlink" title="泛型Generic"></a>泛型Generic</h6><p>不指定泛型的容器，可以存放任何类型的元素；</p>
<p>指定了泛型的容器，只能存放指定类型的元素及其子类。</p>
<p><strong>泛型的简写：在JDK7之后，后面的泛型可以用<code>&lt;&gt;</code>来代替。</strong></p>
<h6 id="遍历"><a href="#遍历" class="headerlink" title="遍历"></a>遍历</h6><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>for</td>
<td>for循环遍历</td>
</tr>
<tr>
<td>itertor</td>
<td>迭代器</td>
</tr>
<tr>
<td>for:</td>
<td>增强for循环</td>
</tr>
</tbody>
</table>
</div>
<h5 id="其他集合"><a href="#其他集合" class="headerlink" title="其他集合"></a>其他集合</h5><h6 id="LinkedList"><a href="#LinkedList" class="headerlink" title="LinkedList"></a>LinkedList</h6><p>一个概念：</p>
<p>序列分先进先出<code>FIFO</code>,先进后出<code>FILO</code></p>
<p><code>FIFO</code>在Java中叫做Queue队列；</p>
<p><code>FILO</code>在Java中叫做Stack栈。</p>
<p>双向链表-Deque</p>
<p>队列-Queue</p>
<div class="table-container">
<table>
<thead>
<tr>
<th>方法名</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>offer</td>
<td>在最后添加元素</td>
</tr>
<tr>
<td>poll</td>
<td>取出第一个元素</td>
</tr>
<tr>
<td>peek</td>
<td>查看第一个元素</td>
</tr>
</tbody>
</table>
</div>
<h6 id="二叉树"><a href="#二叉树" class="headerlink" title="二叉树"></a>二叉树</h6><h6 id="HashMap"><a href="#HashMap" class="headerlink" title="HashMap"></a>HashMap</h6><ul>
<li>HashMap的键值对</li>
<li>键不能重复，值可以重复</li>
</ul>
<h6 id="HashSet"><a href="#HashSet" class="headerlink" title="HashSet"></a>HashSet</h6><ul>
<li>元素不能重复</li>
<li>没有顺序</li>
<li>遍历</li>
</ul>
<h6 id="Collection"><a href="#Collection" class="headerlink" title="Collection"></a>Collection</h6><p>它是一个接口。</p>
<p>Collection是Set，List，Queue和Deque的接口。</p>
<h6 id="Collections"><a href="#Collections" class="headerlink" title="Collections"></a>Collections</h6><p>它是一个容器的工具类。</p>
<div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>reverse</td>
<td>反转</td>
</tr>
<tr>
<td>shuffle</td>
<td>混淆</td>
</tr>
<tr>
<td>sort</td>
<td>排序</td>
</tr>
<tr>
<td>swap</td>
<td>交换</td>
</tr>
<tr>
<td>rotate</td>
<td>滚动</td>
</tr>
<tr>
<td>synchronizedList</td>
<td>线程安全化</td>
</tr>
</tbody>
</table>
</div>
<h5 id="关系和区别"><a href="#关系和区别" class="headerlink" title="关系和区别"></a>关系和区别</h5><h6 id="ArrayList-vs-HashSet"><a href="#ArrayList-vs-HashSet" class="headerlink" title="ArrayList vs HashSet"></a>ArrayList vs HashSet</h6><ul>
<li>是否有顺序</li>
<li>是否重复</li>
</ul>
<h6 id="ArrayList-vs-LinkedList"><a href="#ArrayList-vs-LinkedList" class="headerlink" title="ArrayList vs LinkedList"></a>ArrayList vs LinkedList</h6><ul>
<li>插入数据</li>
<li>定位数据</li>
</ul>
<h6 id="HashMap-vs-HashTable"><a href="#HashMap-vs-HashTable" class="headerlink" title="HashMap vs HashTable"></a>HashMap vs HashTable</h6><ul>
<li>HashMap可能存放<code>null</code>，HashTable不可以；</li>
<li>HashMap不是线程安全的类，HashTable是线程安全的。</li>
</ul>
<h6 id="几种set"><a href="#几种set" class="headerlink" title="几种set"></a>几种set</h6><ul>
<li>HashSet：无序的</li>
<li>LinkedHashSet：按照插入顺序</li>
<li>TreeSet：从小到大排序</li>
</ul>
<h5 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h5><h6 id="HashCode原理"><a href="#HashCode原理" class="headerlink" title="HashCode原理"></a>HashCode原理</h6><ul>
<li>List查找的低效率</li>
<li>HashMap的性能表现</li>
<li>分析HashMap性能卓越的原因</li>
<li>HashSet判断是否重复</li>
</ul>
<h6 id="比较器"><a href="#比较器" class="headerlink" title="比较器"></a>比较器</h6><ul>
<li>Comparator</li>
<li>Comparable</li>
</ul>
<h6 id="聚合操作"><a href="#聚合操作" class="headerlink" title="聚合操作"></a>聚合操作</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> lambda;</span><br><span class="line">  </span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.Collections;</span><br><span class="line"><span class="keyword">import</span> java.util.Comparator;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"><span class="keyword">import</span> java.util.Random;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">import</span> charactor.Hero;</span><br><span class="line">  </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestAggregate</span> {</span><br><span class="line">  </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">        <span class="type">Random</span> <span class="variable">r</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Random</span>();</span><br><span class="line">        List&lt;Hero&gt; heros = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;Hero&gt;();</span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; <span class="number">10</span>; i++) {</span><br><span class="line">            heros.add(<span class="keyword">new</span> <span class="title class_">Hero</span>(<span class="string">"hero "</span> + i, r.nextInt(<span class="number">1000</span>), r.nextInt(<span class="number">100</span>)));</span><br><span class="line">        }</span><br><span class="line"> </span><br><span class="line">        System.out.println(<span class="string">"初始化集合后的数据 (最后一个数据重复)："</span>);</span><br><span class="line">        System.out.println(heros);</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//传统方式</span></span><br><span class="line">        Collections.sort(heros,<span class="keyword">new</span> <span class="title class_">Comparator</span>&lt;Hero&gt;() {</span><br><span class="line">            <span class="meta">@Override</span></span><br><span class="line">            <span class="keyword">public</span> <span class="type">int</span> <span class="title function_">compare</span><span class="params">(Hero o1, Hero o2)</span> {</span><br><span class="line">                <span class="keyword">return</span> (<span class="type">int</span>) (o2.hp-o1.hp);</span><br><span class="line">            }</span><br><span class="line">        });</span><br><span class="line">         </span><br><span class="line">        <span class="type">Hero</span> <span class="variable">hero</span> <span class="operator">=</span> heros.get(<span class="number">2</span>);</span><br><span class="line">        System.out.println(<span class="string">"通过传统方式找出来的hp第三高的英雄名称是:"</span> + hero.name);</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//聚合方式</span></span><br><span class="line">        <span class="type">String</span> <span class="variable">name</span> <span class="operator">=</span>heros</span><br><span class="line">            .stream()</span><br><span class="line">            .sorted((h1,h2)-&gt;h1.hp&gt;h2.hp?-<span class="number">1</span>:<span class="number">1</span>)</span><br><span class="line">            .skip(<span class="number">2</span>)</span><br><span class="line">            .map(h-&gt;h.getName())</span><br><span class="line">            .findFirst()</span><br><span class="line">            .get();</span><br><span class="line"> </span><br><span class="line">        System.out.println(<span class="string">"通过聚合操作找出来的hp第三高的英雄名称是:"</span> + name);</span><br><span class="line">         </span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h4 id="泛型"><a href="#泛型" class="headerlink" title="泛型"></a>泛型</h4><h5 id="集合中的泛型"><a href="#集合中的泛型" class="headerlink" title="集合中的泛型"></a>集合中的泛型</h5><ul>
<li>不使用泛型</li>
<li>使用泛型</li>
<li>子类对象</li>
<li>泛型的简写</li>
</ul>
<h5 id="支持泛型的类"><a href="#支持泛型的类" class="headerlink" title="支持泛型的类"></a>支持泛型的类</h5><ul>
<li>不支持泛型的Stack</li>
<li>支持泛型的Stack</li>
</ul>
<h5 id="通配符"><a href="#通配符" class="headerlink" title="通配符"></a>通配符</h5><ul>
<li>? extends</li>
<li>? super</li>
<li>泛型通配符 ?</li>
</ul>
<h5 id="泛型转型"><a href="#泛型转型" class="headerlink" title="泛型转型"></a>泛型转型</h5><ul>
<li>对象转型</li>
<li>子类泛型转父类泛型</li>
<li>假设可以转型成功</li>
</ul>
<h4 id="JDBC"><a href="#JDBC" class="headerlink" title="JDBC"></a>JDBC</h4><p>Java data base connection指通过java访问数据库。</p>
<h6 id="CRUD"><a href="#CRUD" class="headerlink" title="CRUD"></a>CRUD</h6><ul>
<li>增加 create</li>
<li>读取查询 retrieve</li>
<li>更新 update</li>
<li>删除 delete</li>
</ul>
<h6 id="预编译-statement"><a href="#预编译-statement" class="headerlink" title="预编译 statement"></a>预编译 statement</h6><h6 id="事务"><a href="#事务" class="headerlink" title="事务"></a>事务</h6><h6 id="ORM-Object-Relationship-Database-Mapping"><a href="#ORM-Object-Relationship-Database-Mapping" class="headerlink" title="ORM(Object Relationship Database Mapping)"></a>ORM(Object Relationship Database Mapping)</h6><h6 id="Dao-data-access-object"><a href="#Dao-data-access-object" class="headerlink" title="Dao(data access object)"></a>Dao(data access object)</h6><h6 id="数据库连接池"><a href="#数据库连接池" class="headerlink" title="数据库连接池"></a>数据库连接池</h6><p>数据库连接池原理—使用池</p>
<blockquote>
<p>与传统方式不同，连接池在使用之前，就会创建好一定数量的连接。<br>如果有任何线程需要使用连接，那么就从连接池里面<strong>借用</strong>，<strong>而不是自己重新创建</strong>.<br>使用完毕后，又把这个连接<strong>归还</strong>给连接池供下一次或者其他线程使用。<br>倘若发生多线程并发情况，连接池里的连接被<strong>借用光</strong>了，那么其他线程就会临时等待，直到有连接被<strong>归还</strong>回来，再继续使用。<br>整个过程，这些连接都<strong>不会被关闭</strong>，而是不断的被循环使用，从而节约了启动和关闭连接的时间。</p>
</blockquote>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2021/03/11/java%E5%9F%BA%E7%A1%80/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/03/11/java%E5%9F%BA%E7%A1%80/" class="post-title-link" itemprop="url">java基础</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-11 09:32:05" itemprop="dateCreated datePublished" datetime="2021-03-11T09:32:05+08:00">2021-03-11</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>7.2k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>7 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="操作符"><a href="#操作符" class="headerlink" title="操作符"></a>操作符</h4><h5 id="算数操作符"><a href="#算数操作符" class="headerlink" title="算数操作符"></a>算数操作符</h5><p>常见的基本操作符有 <code>+ - * / %</code>，自增自减（<code>++ --</code>）。</p>
<p><strong>如果有任何运算单元的长度超过<code>int</code>，那么运算结果就按照最长的长度计算。</strong></p>
<p><strong>如果任何运算单元的长度都不超过<code>int</code>，那么运算结果就按照<code>int</code>来计算。</strong></p>
<h6 id="i-i的区别"><a href="#i-i的区别" class="headerlink" title="i++, ++i的区别"></a><code>i++, ++i的区别</code></h6><ul>
<li><code>i++</code>：先取值，再运算。</li>
<li><code>++i</code>：先运算，再取值。</li>
</ul>
<h5 id="关系操作符"><a href="#关系操作符" class="headerlink" title="关系操作符"></a>关系操作符</h5><p>比较两个变量之间的关系</p>
<p>常见的关系操作符有<code>&gt;, &gt;=, &lt;, &lt;=, ==, !=</code>等等。</p>
<h5 id="逻辑操作符"><a href="#逻辑操作符" class="headerlink" title="逻辑操作符"></a>逻辑操作符</h5><p>常见的逻辑操作符有<code>&amp;, &amp;&amp;(短路与), |, ||(短路或), !, ^(异或)</code>。</p>
<p><code>^（异或）</code>：两边不同，返回真；两边相同，返回假。</p>
<h5 id="位操作符"><a href="#位操作符" class="headerlink" title="位操作符"></a>位操作符</h5><div class="table-container">
<table>
<thead>
<tr>
<th>符号</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>`</td>
<td>`</td>
<td>位或</td>
</tr>
<tr>
<td><code>&amp;</code></td>
<td>位与</td>
</tr>
<tr>
<td><code>^</code></td>
<td>异或</td>
</tr>
<tr>
<td><code>~</code></td>
<td>取非</td>
</tr>
<tr>
<td><code>&lt;&lt;</code></td>
<td>左移</td>
</tr>
<tr>
<td><code>&gt;&gt;</code></td>
<td>右移</td>
</tr>
<tr>
<td><code>&gt;&gt;&gt;</code></td>
<td>无符号右移</td>
</tr>
</tbody>
</table>
</div>
<h5 id="赋值操作符"><a href="#赋值操作符" class="headerlink" title="赋值操作符"></a>赋值操作符</h5><div class="table-container">
<table>
<thead>
<tr>
<th>符号</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>=</td>
<td>赋值操作</td>
</tr>
<tr>
<td>+=</td>
<td>对本身进行运算，并赋值</td>
</tr>
<tr>
<td>-=</td>
<td></td>
</tr>
<tr>
<td>*=</td>
<td></td>
</tr>
<tr>
<td>/=</td>
<td></td>
</tr>
<tr>
<td>%=</td>
<td></td>
</tr>
<tr>
<td>……</td>
</tr>
</tbody>
</table>
</div>
<h5 id="三元操作符"><a href="#三元操作符" class="headerlink" title="三元操作符"></a>三元操作符</h5><p><code>? :</code></p>
<p>一个栗子：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="variable">k</span> <span class="operator">=</span> i &lt; j ? <span class="number">99</span> : <span class="number">88</span>;</span><br></pre></td></tr></table></figure>
<h4 id="控制流程"><a href="#控制流程" class="headerlink" title="控制流程"></a>控制流程</h4><h5 id="条件判断if"><a href="#条件判断if" class="headerlink" title="条件判断if"></a>条件判断<code>if</code></h5><p>一个<code>if</code>的坑：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">HelloWorld</span> {</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">        <span class="type">boolean</span> <span class="variable">b</span> <span class="operator">=</span> <span class="literal">false</span>;</span><br><span class="line">        <span class="keyword">if</span> (b);</span><br><span class="line">            System.out.println(<span class="string">"yes"</span>);</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>此时，无论<code>b</code>为true还是false，<code>yes</code>都会被打印出来。</p>
<h5 id="条件判断switch"><a href="#条件判断switch" class="headerlink" title="条件判断switch"></a>条件判断<code>switch</code></h5><p><code>switch</code>可以使用<code>byte, short, int, char, String, enum</code>。</p>
<h5 id="循环判断while"><a href="#循环判断while" class="headerlink" title="循环判断while"></a>循环判断<code>while</code></h5><ul>
<li>while</li>
<li>do…while (至少执行一次循环体)</li>
</ul>
<h5 id="循环语句for"><a href="#循环语句for" class="headerlink" title="循环语句for"></a>循环语句<code>for</code></h5><p>一个无限循环的栗子：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(;;) {</span><br><span class="line">    ...</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h5 id="关键字continue-break"><a href="#关键字continue-break" class="headerlink" title="关键字continue break"></a>关键字<code>continue</code> <code>break</code></h5><ul>
<li>continue：当次循环的后面代码停止执行，继续下一次循环。</li>
<li>break：结束当前的循环</li>
</ul>
<h5 id="结束外部循环"><a href="#结束外部循环" class="headerlink" title="结束外部循环"></a>结束外部循环</h5><ul>
<li><p>使用boolean变量结束外部循环</p>
<p>一个栗子：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">HelloWorld</span> {</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">        <span class="type">boolean</span> <span class="variable">breakout</span> <span class="operator">=</span> <span class="literal">false</span>; <span class="comment">//是否终止外部循环的标记</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; <span class="number">10</span>; i++) {</span><br><span class="line"> </span><br><span class="line">            <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">j</span> <span class="operator">=</span> <span class="number">0</span>; j &lt; <span class="number">10</span>; j++) {</span><br><span class="line">                System.out.println(i + <span class="string">":"</span> + j);</span><br><span class="line">                <span class="keyword">if</span> (<span class="number">0</span> == j % <span class="number">2</span>) {</span><br><span class="line">                    breakout = <span class="literal">true</span>; <span class="comment">//终止外部循环的标记设置为true</span></span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                }</span><br><span class="line">            }</span><br><span class="line">            <span class="keyword">if</span> (breakout) <span class="comment">//判断是否终止外部循环</span></span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">        }</span><br><span class="line"> </span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用标签结束外部循环</p>
<p>一个栗子：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">HelloWorld</span> {</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">          </span><br><span class="line">        <span class="comment">//打印单数    </span></span><br><span class="line">        outloop: <span class="comment">//outloop这个标示是可以自定义的比如outloop1,ol2,out5</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; <span class="number">10</span>; i++) {</span><br><span class="line">             </span><br><span class="line">            <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">j</span> <span class="operator">=</span> <span class="number">0</span>; j &lt; <span class="number">10</span>; j++) {</span><br><span class="line">                System.out.println(i+<span class="string">":"</span>+j);</span><br><span class="line">                <span class="keyword">if</span>(<span class="number">0</span>==j%<span class="number">2</span>) </span><br><span class="line">                    <span class="keyword">break</span> outloop; <span class="comment">//如果是双数，结束外部循环</span></span><br><span class="line">            }</span><br><span class="line">             </span><br><span class="line">        }</span><br><span class="line">         </span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h4 id="数组"><a href="#数组" class="headerlink" title="数组"></a>数组</h4><p>定义：数组是一个固定长度的，包含了相同类型数据的容器。</p>
<h5 id="赋值"><a href="#赋值" class="headerlink" title="赋值"></a>赋值</h5><ul>
<li>分配空间和赋值分布进行</li>
<li>分配空间的同时赋值</li>
</ul>
<h5 id="排序"><a href="#排序" class="headerlink" title="排序"></a>排序</h5><ul>
<li>选择排序</li>
<li>冒泡排序</li>
</ul>
<h5 id="增强for循环"><a href="#增强for循环" class="headerlink" title="增强for循环"></a>增强for循环</h5><p><strong>注意：增强for循环只能用来取值，不能用来修改数组里的值。</strong></p>
<p>一个栗子：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">HelloWorld</span> {</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">        <span class="type">int</span> values [] = <span class="keyword">new</span> <span class="title class_">int</span>[]{<span class="number">18</span>,<span class="number">62</span>,<span class="number">68</span>,<span class="number">82</span>,<span class="number">65</span>,<span class="number">9</span>};</span><br><span class="line">        <span class="comment">//常规遍历</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; values.length; i++) {</span><br><span class="line">            <span class="type">int</span> <span class="variable">each</span> <span class="operator">=</span> values[i];</span><br><span class="line">            System.out.println(each);</span><br><span class="line">        }</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//增强型for循环遍历</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> each : values) {</span><br><span class="line">            System.out.println(each);</span><br><span class="line">        }</span><br><span class="line">         </span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h5 id="复制数组"><a href="#复制数组" class="headerlink" title="复制数组"></a>复制数组</h5><p>数组的长度是不可变的，一旦分配好空间，是多长，就是多长，不能增加也不能减少。</p>
<p>把一个数组的值复制到另一个数组中：</p>
<p><code>System.arraycopy(src, srcPos, dest, destPos, length)</code></p>
<ul>
<li>src: 源数组</li>
<li>srcPos: 从源数组复制数据的起始位置</li>
<li>dest: 目标数组</li>
<li>destPos: 复制到目标数组的起始位置</li>
<li>length: 复制的长度</li>
</ul>
<h5 id="二维数组"><a href="#二维数组" class="headerlink" title="二维数组"></a>二维数组</h5><p>又叫数组的数组，即二维数组中的每一个元素，也是一个（一维）数组。</p>
<h6 id="初始化二维数组"><a href="#初始化二维数组" class="headerlink" title="初始化二维数组"></a>初始化二维数组</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">HelloWorld</span> {</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">       <span class="comment">//初始化二维数组，</span></span><br><span class="line">       <span class="type">int</span>[][] a = <span class="keyword">new</span> <span class="title class_">int</span>[<span class="number">2</span>][<span class="number">3</span>]; <span class="comment">//有两个一维数组，每个一维数组的长度是3</span></span><br><span class="line">       a[<span class="number">1</span>][<span class="number">2</span>] = <span class="number">5</span>;  <span class="comment">//可以直接访问一维数组，因为已经分配了空间</span></span><br><span class="line">          </span><br><span class="line">       <span class="comment">//只分配了二维数组</span></span><br><span class="line">       <span class="type">int</span>[][] b = <span class="keyword">new</span> <span class="title class_">int</span>[<span class="number">2</span>][]; <span class="comment">//有两个一维数组，每个一维数组的长度暂未分配</span></span><br><span class="line">       b[<span class="number">0</span>]  =<span class="keyword">new</span> <span class="title class_">int</span>[<span class="number">3</span>]; <span class="comment">//必须事先分配长度，才可以访问</span></span><br><span class="line">       b[<span class="number">0</span>][<span class="number">2</span>] = <span class="number">5</span>;</span><br><span class="line">        </span><br><span class="line">       <span class="comment">//指定内容的同时，分配空间</span></span><br><span class="line">       <span class="type">int</span>[][] c = <span class="keyword">new</span> <span class="title class_">int</span>[][]{</span><br><span class="line">               {<span class="number">1</span>,<span class="number">2</span>,<span class="number">4</span>},</span><br><span class="line">               {<span class="number">4</span>,<span class="number">5</span>},</span><br><span class="line">               {<span class="number">6</span>,<span class="number">7</span>,<span class="number">8</span>,<span class="number">9</span>}</span><br><span class="line">       };</span><br><span class="line"> </span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h5 id="Arrays"><a href="#Arrays" class="headerlink" title="Arrays"></a>Arrays</h5><p>Arrays是针对数组的工具类，可以进行排序、查找、复制填充等功能。</p>
<h4 id="类和对象"><a href="#类和对象" class="headerlink" title="类和对象"></a>类和对象</h4><p><code>引用</code>的概念:如果一个变量的类型是<code>类类型</code>，而非基本类型，那么该变量又叫做引用。</p>
<h5 id="引用"><a href="#引用" class="headerlink" title="引用"></a>引用</h5><ol>
<li><p>多个引用，一个对象</p>
</li>
<li><p>一个引用，多个对象</p>
<p><strong>一个引用，同一时间，只能指向一个对象。</strong></p>
</li>
</ol>
<h5 id="继承"><a href="#继承" class="headerlink" title="继承"></a>继承</h5><p>将多个类中共性的东西提取出来，作为一个统一的父类。</p>
<h5 id="方法重载"><a href="#方法重载" class="headerlink" title="方法重载"></a>方法重载</h5><p>定义：方法名一样，但是参数的类型不一样，或参数的个数不一样。</p>
<h6 id="可变数量的参数"><a href="#可变数量的参数" class="headerlink" title="可变数量的参数"></a>可变数量的参数</h6><p>一个栗子：</p>
<p><code>public void attack(String ..strs)</code>,在方法里面，可使用操作<code>数组</code>的方式来处理参数<code>strs</code>。</p>
<h5 id="构造方法"><a href="#构造方法" class="headerlink" title="构造方法"></a>构造方法</h5><h5 id="this"><a href="#this" class="headerlink" title="this"></a>this</h5><p>this代表当前对象。</p>
<h5 id="传参"><a href="#传参" class="headerlink" title="传参"></a>传参</h5><p>因变量有基本类型和类类型两种类型，故参数也分为基本类型传参和类类型传参。</p>
<h6 id="引用与"><a href="#引用与" class="headerlink" title="引用与="></a>引用与=</h6><p>基本类型之间的<code>=</code>叫做赋值；</p>
<p>类类型之间的<code>=</code>叫做引用。</p>
<h5 id="访问修饰符"><a href="#访问修饰符" class="headerlink" title="访问修饰符"></a>访问修饰符</h5><div class="table-container">
<table>
<thead>
<tr>
<th>修饰符</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>private</td>
<td>私有的</td>
</tr>
<tr>
<td>“package”（friendly、default）</td>
<td>不写</td>
</tr>
<tr>
<td>protected</td>
<td>受保护的</td>
</tr>
<tr>
<td>public</td>
<td>公共的</td>
</tr>
</tbody>
</table>
</div>
<p><img src="http://localhost:4000/2021/03/11/java%E5%9F%BA%E7%A1%80/001.png" alt></p>
<h5 id="类属性"><a href="#类属性" class="headerlink" title="类属性"></a>类属性</h5><p>当一个属性被<code>static</code>修饰的时候，就叫做<code>类属性</code>，又叫做<code>静态属性</code>。</p>
<p>当一个属性被声明成类属性，那么所有的对象，都共享一个值。</p>
<p>与对象属性对比：</p>
<ul>
<li>不同对象的 <strong>对象属性</strong> 的值可能不一样；</li>
<li>但是所有对象的类属性的值，都是一样的。</li>
</ul>
<p>类属性，又叫静态属性。</p>
<p>对象属性，又叫实例属性，非静态属性。</p>
<h5 id="类方法"><a href="#类方法" class="headerlink" title="类方法"></a>类方法</h5><p>类方法又叫静态方法；</p>
<p>对象方法又叫实例方法，非静态方法。</p>
<p>访问一个对象方法，必须建立在有一个对象的基础上，</p>
<p>访问类方法，不需要对象的存在，直接就可以访问。</p>
<h5 id="属性初始化"><a href="#属性初始化" class="headerlink" title="属性初始化"></a>属性初始化</h5><ul>
<li>声明该属性的时候初始化</li>
<li>构造方法中初始化</li>
<li>初始化块</li>
</ul>
<h5 id="单例模式"><a href="#单例模式" class="headerlink" title="单例模式"></a>单例模式</h5><p>定义：又叫做<code>Singleton</code>模式，指的是一个类，在一个JVM中，只有一个实例存在。</p>
<h6 id="饿汉式和懒汉式"><a href="#饿汉式和懒汉式" class="headerlink" title="饿汉式和懒汉式"></a>饿汉式和懒汉式</h6><ul>
<li>饿汉式：是立即加载的方式，无论是否会用到这个对象，都会加载。</li>
<li>懒汉式：是延迟加载的方式，只有使用的时候才会加载。</li>
</ul>
<h5 id="枚举"><a href="#枚举" class="headerlink" title="枚举"></a>枚举</h5><p>枚举（menu）是一种特殊的 <strong>类</strong>，使用枚举可以很方便的定义常量。</p>
<h4 id="接口和继承"><a href="#接口和继承" class="headerlink" title="接口和继承"></a>接口和继承</h4><h5 id="接口"><a href="#接口" class="headerlink" title="接口"></a>接口</h5><p>接口就像是一种约定。</p>
<h5 id="对象转型"><a href="#对象转型" class="headerlink" title="对象转型"></a>对象转型</h5><ol>
<li><p>明确引用类型和对象类型的概念</p>
<p>通常情况下，引用类型和对象类型的类型是一致的。</p>
</li>
<li><p>子类转父类（向上转型）</p>
<p>将子类转换为父类，总是成功的。</p>
</li>
<li><p>父类转子类（向下转型）</p>
<p>需要强制类型转换，不一定能转换成功。</p>
</li>
<li><p>没有继承关系的两个类，互相转换，<span style="color:red;">一定会失败。</span></p>
</li>
<li><p>实现类转接口（向上转型）</p>
</li>
<li><p>接口转实现类（向下转型）</p>
</li>
<li><p><code>instanceof</code>关键字</p>
<p><code>instanceof Map</code> 判断一个引用所指向的对象，是否为Map类型，或者Map类型的子类。</p>
</li>
</ol>
<h5 id="重写"><a href="#重写" class="headerlink" title="重写"></a>重写</h5><p>子类可以继承父类的对象方法，在继承后，重复提供该方法，就叫做方法的重写，也叫覆盖。</p>
<h5 id="多态"><a href="#多态" class="headerlink" title="多态"></a>多态</h5><ul>
<li><p>操作符的多态</p>
<p><code>+</code>可以作为算数运算，也可以作为字符串连接。</p>
</li>
<li><p>类的多态</p>
<p>父类引用指向子类的对象。</p>
</li>
</ul>
<h5 id="隐藏"><a href="#隐藏" class="headerlink" title="隐藏"></a>隐藏</h5><p>它与重写类似，方法的重写是子类覆盖父类的<code>对象方法</code>，</p>
<p><code>隐藏</code>就是子类覆盖父类的<code>类方法</code>。</p>
<h5 id="super关键字"><a href="#super关键字" class="headerlink" title="super关键字"></a>super关键字</h5><p><strong>实例化子类，父类的构造方法一定会被调用。</strong></p>
<h5 id="Object类"><a href="#Object类" class="headerlink" title="Object类"></a>Object类</h5><p>它是所有类的父类。</p>
<ul>
<li>toString()</li>
<li>finalize()</li>
<li>equals()</li>
<li>==</li>
<li>hashCode()</li>
<li>getClass()</li>
</ul>
<h5 id="final"><a href="#final" class="headerlink" title="final"></a>final</h5><div class="table-container">
<table>
<thead>
<tr>
<th>修饰什么</th>
<th>意义</th>
</tr>
</thead>
<tbody>
<tr>
<td>类</td>
<td>不能被继承</td>
</tr>
<tr>
<td>方法</td>
<td>不能被重写</td>
</tr>
<tr>
<td>基本类型变量</td>
<td>该变量只有一次赋值机会</td>
</tr>
<tr>
<td>引用</td>
<td>该引用只有一次指向对象的机会</td>
</tr>
</tbody>
</table>
</div>
<p><strong>常量指可以公开，直接访问，不会变化的值。</strong></p>
<h5 id="抽象类"><a href="#抽象类" class="headerlink" title="抽象类"></a>抽象类</h5><p>在类中声明一个方法，这个方法没有方法体，是一个“空”方法。</p>
<p>这样的方法就叫抽象方法，使用修饰符<code>abstract</code>，</p>
<p>当一个类中有抽象方法的时候，该类必须被声明为抽象类。</p>
<p><strong>抽象类可以没有抽象方法。</strong></p>
<h5 id="内部类"><a href="#内部类" class="headerlink" title="内部类"></a>内部类</h5><p>分为四种：</p>
<ol>
<li><p>非静态内部类</p>
<p>非静态内部类可以在类中直接定义。</p>
</li>
<li><p>静态内部类</p>
<p>在一个类里面声明一个静态内部类，在静态内部类中 <strong>不可以访问外部类的实例属性和方法。</strong></p>
</li>
<li><p>匿名类</p>
<p>指声明一个类的同时实例化它，使代码更加简洁精炼。</p>
</li>
<li><p>本地类</p>
<p>本地类可以理解为有名字的匿名类。</p>
<p>一个栗子：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> charactor;</span><br><span class="line">   </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">class</span> <span class="title class_">Hero</span> {</span><br><span class="line">    String name; <span class="comment">//姓名</span></span><br><span class="line">          </span><br><span class="line">    <span class="type">float</span> hp; <span class="comment">//血量</span></span><br><span class="line">          </span><br><span class="line">    <span class="type">float</span> armor; <span class="comment">//护甲</span></span><br><span class="line">          </span><br><span class="line">    <span class="type">int</span> moveSpeed; <span class="comment">//移动速度</span></span><br><span class="line">      </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">void</span> <span class="title function_">attack</span><span class="params">()</span>;</span><br><span class="line">      </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">          </span><br><span class="line">        <span class="comment">//与匿名类的区别在于，本地类有了自定义的类名</span></span><br><span class="line">        <span class="keyword">class</span> <span class="title class_">SomeHero</span> <span class="keyword">extends</span> <span class="title class_">Hero</span>{</span><br><span class="line">            <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">attack</span><span class="params">()</span> {</span><br><span class="line">                System.out.println( name+ <span class="string">" 新的进攻手段"</span>);</span><br><span class="line">            }</span><br><span class="line">        }</span><br><span class="line">         </span><br><span class="line">        <span class="type">SomeHero</span> <span class="variable">h</span>  <span class="operator">=</span><span class="keyword">new</span> <span class="title class_">SomeHero</span>();</span><br><span class="line">        h.name =<span class="string">"地卜师"</span>;</span><br><span class="line">        h.attack();</span><br><span class="line">    }</span><br><span class="line">      </span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p><strong>在匿名类使用外部的局部变量，外部的局部变量必须修饰为<code>final</code>的。</strong></p>
<blockquote>
<p><strong>注：</strong>在jdk8中，已经不需要强制修饰成final了，如果没有写final，不会报错，因为编译器<strong>偷偷的</strong>帮你加上了看不见的final</p>
</blockquote>
<h5 id="默认方法"><a href="#默认方法" class="headerlink" title="默认方法"></a>默认方法</h5><p>默认方法是jdk1.8的新特性，指的是接口也可以提供具体方法了，而不像以前，只能提供抽象方法。</p>
<p>一个栗子：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> charactor;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">Mortal</span> {</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">die</span><span class="params">()</span>;</span><br><span class="line"> </span><br><span class="line">    <span class="keyword">default</span> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">revive</span><span class="params">()</span> {</span><br><span class="line">        System.out.println(<span class="string">"本英雄复活了"</span>);</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h6 id="为什么会有默认方法？"><a href="#为什么会有默认方法？" class="headerlink" title="为什么会有默认方法？"></a>为什么会有默认方法？</h6><blockquote>
<p>假设没有默认方法这种机制，那么如果要为Mortal增加一个新的方法revive,那么所有实现了Mortal接口的类，都需要做改动。</p>
<p>但是引入了默认方法后，原来的类，不需要做任何改动，并且还能<strong>得到</strong>这个默认方法</p>
<p>通过这种手段，就能够很好的扩展新的类，并且做到不影响原来的类</p>
</blockquote>
<h4 id="数字和字符串"><a href="#数字和字符串" class="headerlink" title="数字和字符串"></a>数字和字符串</h4><h5 id="装箱拆箱"><a href="#装箱拆箱" class="headerlink" title="装箱拆箱"></a>装箱拆箱</h5><p>封装类：所有的基本类型，都有对应的类类型。</p>
<p>比如int对应的类是Integer，这种类就叫做封装类。</p>
<h5 id="字符串转换"><a href="#字符串转换" class="headerlink" title="字符串转换"></a>字符串转换</h5><h6 id="数字转字符串"><a href="#数字转字符串" class="headerlink" title="数字转字符串"></a>数字转字符串</h6><ol>
<li>使用String类的静态方法<code>valueOf</code></li>
<li>先把基本类型装箱为对象，然后调用对象的<code>toString</code>方法</li>
</ol>
<h6 id="字符串转数字"><a href="#字符串转数字" class="headerlink" title="字符串转数字"></a>字符串转数字</h6><p>调用Integer的静态方法<code>parseInt</code></p>
<h5 id="数学方法"><a href="#数学方法" class="headerlink" title="数学方法"></a>数学方法</h5><p><code>java.lang.Math</code>提供一些常用的数学运算方法，并且都是以静态方法的形式存在。</p>
<div class="table-container">
<table>
<thead>
<tr>
<th>方法</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>Math.round(1.9)</td>
<td>四舍五入</td>
</tr>
<tr>
<td>Math.random()</td>
<td>得到一个0到1的随机数<code>[0, 1)</code></td>
</tr>
<tr>
<td>Math.sqrt(9)</td>
<td>开方<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align: -0.25ex;" xmlns="http://www.w3.org/2000/svg" width="3.061ex" height="2.398ex" role="img" focusable="false" viewbox="0 -949.5 1353 1060"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="msqrt"><g transform="translate(853,0)"><g data-mml-node="mn"><path data-c="39" d="M352 287Q304 211 232 211Q154 211 104 270T44 396Q42 412 42 436V444Q42 537 111 606Q171 666 243 666Q245 666 249 666T257 665H261Q273 665 286 663T323 651T370 619T413 560Q456 472 456 334Q456 194 396 97Q361 41 312 10T208 -22Q147 -22 108 7T68 93T121 149Q143 149 158 135T173 96Q173 78 164 65T148 49T135 44L131 43Q131 41 138 37T164 27T206 22H212Q272 22 313 86Q352 142 352 280V287ZM244 248Q292 248 321 297T351 430Q351 508 343 542Q341 552 337 562T323 588T293 615T246 625Q208 625 181 598Q160 576 154 546T147 441Q147 358 152 329T172 282Q197 248 244 248Z"/></g></g><g data-mml-node="mo" transform="translate(0,89.5)"><path data-c="221A" d="M95 178Q89 178 81 186T72 200T103 230T169 280T207 309Q209 311 212 311H213Q219 311 227 294T281 177Q300 134 312 108L397 -77Q398 -77 501 136T707 565T814 786Q820 800 834 800Q841 800 846 794T853 782V776L620 293L385 -193Q381 -200 366 -200Q357 -200 354 -197Q352 -195 256 15L160 225L144 214Q129 202 113 190T95 178Z"/></g><rect width="500" height="60" x="853" y="829.5"/></g></g></g></svg></mjx-container></td>
</tr>
<tr>
<td>Math.pow(2, 5)</td>
<td>次方<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align: 0;" xmlns="http://www.w3.org/2000/svg" width="2.119ex" height="1.887ex" role="img" focusable="false" viewbox="0 -833.9 936.6 833.9"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="msup"><g data-mml-node="mn"><path data-c="32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"/></g><g data-mml-node="mn" transform="translate(533,363) scale(0.707)"><path data-c="35" d="M164 157Q164 133 148 117T109 101H102Q148 22 224 22Q294 22 326 82Q345 115 345 210Q345 313 318 349Q292 382 260 382H254Q176 382 136 314Q132 307 129 306T114 304Q97 304 95 310Q93 314 93 485V614Q93 664 98 664Q100 666 102 666Q103 666 123 658T178 642T253 634Q324 634 389 662Q397 666 402 666Q410 666 410 648V635Q328 538 205 538Q174 538 149 544L139 546V374Q158 388 169 396T205 412T256 420Q337 420 393 355T449 201Q449 109 385 44T229 -22Q148 -22 99 32T50 154Q50 178 61 192T84 210T107 214Q132 214 148 197T164 157Z"/></g></g></g></g></svg></mjx-container></td>
</tr>
<tr>
<td>Math.PI</td>
<td>常数π</td>
</tr>
<tr>
<td>Math.E</td>
<td>自然常数</td>
</tr>
</tbody>
</table>
</div>
<h5 id="格式化输出"><a href="#格式化输出" class="headerlink" title="格式化输出"></a>格式化输出</h5><p>一个栗子：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> digit;</span><br><span class="line">  </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestNumber</span> {</span><br><span class="line">  </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line"> </span><br><span class="line">        <span class="type">String</span> <span class="variable">name</span> <span class="operator">=</span><span class="string">"盖伦"</span>;</span><br><span class="line">        <span class="type">int</span> <span class="variable">kill</span> <span class="operator">=</span> <span class="number">8</span>;</span><br><span class="line">        String title=<span class="string">"超神"</span>;</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//直接使用+进行字符串连接，编码感觉会比较繁琐，并且维护性差,易读性差</span></span><br><span class="line">        <span class="type">String</span> <span class="variable">sentence</span> <span class="operator">=</span> name+ <span class="string">" 在进行了连续 "</span> + kill + <span class="string">" 次击杀后，获得了 "</span> + title +<span class="string">" 的称号"</span>;</span><br><span class="line">         </span><br><span class="line">        System.out.println(sentence);</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//使用格式化输出</span></span><br><span class="line">        <span class="comment">//%s表示字符串，%d表示数字,%n表示换行</span></span><br><span class="line">        <span class="type">String</span> <span class="variable">sentenceFormat</span> <span class="operator">=</span><span class="string">"%s 在进行了连续 %d 次击杀后，获得了 %s 的称号%n"</span>;</span><br><span class="line">        System.out.printf(sentenceFormat,name,kill,title);</span><br><span class="line">         </span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h6 id="printf和format"><a href="#printf和format" class="headerlink" title="printf和format"></a>printf和format</h6><h6 id="换行符"><a href="#换行符" class="headerlink" title="换行符"></a>换行符</h6><div class="table-container">
<table>
<thead>
<tr>
<th>系统</th>
<th>符号</th>
</tr>
</thead>
<tbody>
<tr>
<td>DOS和Windows</td>
<td><code>\r\n</code></td>
</tr>
<tr>
<td>Linux</td>
<td><code>\n</code></td>
</tr>
<tr>
<td>Mac</td>
<td><code>\r</code></td>
</tr>
</tbody>
</table>
</div>
<p><strong>为了使得同一个java程序的换行符在所有的操作系统都有一样的表现，使用<code>%n</code>，就可以做到平台无关的换行。</strong></p>
<p>一个栗子:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> digit;</span><br><span class="line">  </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestNumber</span> {</span><br><span class="line">  </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line"> </span><br><span class="line">        System.out.printf(<span class="string">"这是换行符%n"</span>);</span><br><span class="line">        System.out.printf(<span class="string">"这是换行符%n"</span>);</span><br><span class="line">         </span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h6 id="总长度，左对齐，补0，千位分隔符，小数点位数，本地化表达"><a href="#总长度，左对齐，补0，千位分隔符，小数点位数，本地化表达" class="headerlink" title="总长度，左对齐，补0，千位分隔符，小数点位数，本地化表达"></a>总长度，左对齐，补0，千位分隔符，小数点位数，本地化表达</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> digit;</span><br><span class="line">  </span><br><span class="line"><span class="keyword">import</span> java.util.Locale;</span><br><span class="line">   </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestNumber</span> {</span><br><span class="line">   </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">        <span class="type">int</span> <span class="variable">year</span> <span class="operator">=</span> <span class="number">2020</span>;</span><br><span class="line">        <span class="comment">//总长度，左对齐，补0，千位分隔符，小数点位数，本地化表达</span></span><br><span class="line">          </span><br><span class="line">        <span class="comment">//直接打印数字</span></span><br><span class="line">        System.out.format(<span class="string">"%d%n"</span>,year);</span><br><span class="line">        <span class="comment">//总长度是8,默认右对齐</span></span><br><span class="line">        System.out.format(<span class="string">"%8d%n"</span>,year);</span><br><span class="line">        <span class="comment">//总长度是8,左对齐</span></span><br><span class="line">        System.out.format(<span class="string">"%-8d%n"</span>,year);</span><br><span class="line">        <span class="comment">//总长度是8,不够补0</span></span><br><span class="line">        System.out.format(<span class="string">"%08d%n"</span>,year);</span><br><span class="line">        <span class="comment">//千位分隔符</span></span><br><span class="line">        System.out.format(<span class="string">"%,8d%n"</span>,year*<span class="number">10000</span>);</span><br><span class="line">  </span><br><span class="line">        <span class="comment">//小数点位数</span></span><br><span class="line">        System.out.format(<span class="string">"%.2f%n"</span>,Math.PI);</span><br><span class="line">          </span><br><span class="line">        <span class="comment">//不同国家的千位分隔符</span></span><br><span class="line">        System.out.format(Locale.FRANCE,<span class="string">"%,.2f%n"</span>,Math.PI*<span class="number">10000</span>);</span><br><span class="line">        System.out.format(Locale.US,<span class="string">"%,.2f%n"</span>,Math.PI*<span class="number">10000</span>);</span><br><span class="line">        System.out.format(Locale.UK,<span class="string">"%,.2f%n"</span>,Math.PI*<span class="number">10000</span>);</span><br><span class="line">          </span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h5 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h5><p>创建字符串的手段：</p>
<ul>
<li>每当有一个 <strong>字面值</strong> 出现的时候，虚拟机就会创建一个字符串。</li>
<li>调用 String 的构造方法创建一个字符串对象。</li>
<li>通过 <code>+</code> 加号进行字符串拼接也会创建新的字符串对象。</li>
</ul>
<p><strong>String类是final修改的，故不能被继承。</strong></p>
<h4 id="日期"><a href="#日期" class="headerlink" title="日期"></a>日期</h4><h5 id="Date类"><a href="#Date类" class="headerlink" title="Date类"></a>Date类</h5><p><strong>注意：指的是<code>java.util.Date</code></strong></p>
<p>时间原点概念</p>
<blockquote>
<p>所有的数据类型，无论是整数，布尔，浮点数还是字符串，最后都需要以数字的形式表现出来。</p>
<p>日期类型也不例外，换句话说，一个日期，比如2020年10月1日，在计算机里，会用一个数字来代替。</p>
<p>那么最特殊的一个数字，就是零. 零这个数字，就代表Java中的时间原点，其对应的日期是1970年1月1日 8点0分0秒 。 (为什么是8点，因为中国的太平洋时区是UTC-8，刚好和格林威治时间差8个小时)</p>
<p>为什么对应1970年呢？ 因为1969年发布了第一个 UNIX 版本：AT&amp;T，综合考虑，当时就把1970年当做了时间原点。</p>
<p>所有的日期，都是以为这个0点为基准，每过一毫秒，就+1</p>
</blockquote>
<h5 id="日期的格式化"><a href="#日期的格式化" class="headerlink" title="日期的格式化"></a>日期的格式化</h5><h5 id="Calendar"><a href="#Calendar" class="headerlink" title="Calendar"></a>Calendar</h5>
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2021/03/10/helloWorld/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/03/10/helloWorld/" class="post-title-link" itemprop="url">helloWorld</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-10 16:15:24" itemprop="dateCreated datePublished" datetime="2021-03-10T16:15:24+08:00">2021-03-10</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>458</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="jdk配置成功后的效果"><a href="#jdk配置成功后的效果" class="headerlink" title="jdk配置成功后的效果"></a>jdk配置成功后的效果</h4><p>打开命令行窗口，在其中执行命令 <code>java -version</code>, <strong>注意：<code>-version</code>是小写，不能使用大写，java后面有一个空格。</strong></p>
<p>配置成功后，会出现版本信息 <span style="color:#F1B054;">java version “1.8.0_65”</span>。</p>
<h4 id="环境变量配置"><a href="#环境变量配置" class="headerlink" title="环境变量配置"></a>环境变量配置</h4><p>新建一个环境变量 <code>JAVA_HOME</code>,为<code>JDK</code>的目录路径。</p>
<p>修改变量<code>Path</code>，在最前面加上<code>%JAVA_HOME%\bin;</code></p>
<h5 id="问题：明明存在Hello这个类，并且也有主方法，可是运行就出现找不到或者无法加载类Hello，或者Class-Not-Found异常？"><a href="#问题：明明存在Hello这个类，并且也有主方法，可是运行就出现找不到或者无法加载类Hello，或者Class-Not-Found异常？" class="headerlink" title="问题：明明存在Hello这个类，并且也有主方法，可是运行就出现找不到或者无法加载类Hello，或者Class Not Found异常？"></a>问题：明明存在Hello这个类，并且也有主方法，可是运行就出现找不到或者无法加载类Hello，或者Class Not Found异常？</h5><ul>
<li>重新构建项目</li>
<li>可能项目导入的包不存在</li>
</ul>
<h4 id="变量"><a href="#变量" class="headerlink" title="变量"></a>变量</h4><h5 id="java基本类型"><a href="#java基本类型" class="headerlink" title="java基本类型"></a>java基本类型</h5><ul>
<li>byte</li>
<li>short</li>
<li>int</li>
<li>long</li>
<li>char</li>
<li>float</li>
<li>double</li>
</ul>
<h5 id="字面值"><a href="#字面值" class="headerlink" title="字面值"></a>字面值</h5><h5 id="浮点数字面值"><a href="#浮点数字面值" class="headerlink" title="浮点数字面值"></a>浮点数字面值</h5><p>当以<code>f</code>或<code>F</code>结尾的时候，就表示一个<code>float</code>类型的浮点数，否则就是<code>double</code>类型（以<code>d</code>或<code>D</code>结尾，写不写都可以）。</p>
<p>浮点数还可以用<code>E</code>或<code>e</code>表示(科学计数法)。</p>
<p><code>e2</code>表示<code>10</code>的二次方，即<code>100</code>。</p>
<p>如<code>1.234e2 = 1.234 * 100</code>。</p>
<h5 id="类型转换"><a href="#类型转换" class="headerlink" title="类型转换"></a>类型转换</h5><p>小类型向大类型自动转换，大类型向小类型需 <strong>强制转换</strong>.</p>
<p>强制转换可能产生精度缺失。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2021/03/10/rrs%E5%85%A5%E9%97%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/03/10/rrs%E5%85%A5%E9%97%A8/" class="post-title-link" itemprop="url">rrs入门</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-10 14:05:12" itemprop="dateCreated datePublished" datetime="2021-03-10T14:05:12+08:00">2021-03-10</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>44</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="检查一个网站是否含有rss链接"><a href="#检查一个网站是否含有rss链接" class="headerlink" title="检查一个网站是否含有rss链接"></a>检查一个网站是否含有rss链接</h4><p>在网址后面添加如下内容</p>
<ul>
<li><code>/rss</code></li>
<li><code>/feed</code></li>
<li><code>/atom.xml</code></li>
</ul>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2021/03/10/rrs%E5%85%A5%E9%97%A8/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2021/03/08/%E7%AE%97%E6%B3%95%E6%80%9D%E6%83%B33/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/03/08/%E7%AE%97%E6%B3%95%E6%80%9D%E6%83%B33/" class="post-title-link" itemprop="url">算法思想3</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-08 10:25:23" itemprop="dateCreated datePublished" datetime="2021-03-08T10:25:23+08:00">2021-03-08</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>2.7k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>2 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="搜索算法"><a href="#搜索算法" class="headerlink" title="搜索算法"></a>搜索算法</h4><h5 id="分类"><a href="#分类" class="headerlink" title="分类"></a>分类</h5><ul>
<li>枚举算法<ul>
<li>列举问题的所有状态从而寻找符合问题的解的方法</li>
<li>适合用于状态较少，比较简单的问题上</li>
</ul>
</li>
<li>广度优先搜索<ul>
<li>从初始点开始，根据规则展开第一层节点，并检查目标节点是否在这些节点上，若没有，再将所有的第一层的节点逐一展开，得到第二层节点，如没有，则扩展下去，直到发现目标节点为止。</li>
<li>比较适合求最少步骤或最短解序列的题目</li>
<li>一般设置一个队列 <strong>queue</strong>，将初始点放入队列中，然后从队列头取出一个节点，检查是否是目标节点，如不是则进行扩展，将扩展出的所有节点放到队尾，然后再从队列头取出一个节点，直至找到目标节点。</li>
</ul>
</li>
</ul>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2021/03/08/%E7%AE%97%E6%B3%95%E6%80%9D%E6%83%B33/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/13/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/13/">13</a><span class="page-number current">14</span><a class="page-number" href="/page/15/">15</a><span class="space">&hellip;</span><a class="page-number" href="/page/35/">35</a><a class="extend next" rel="next" href="/page/15/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">田园隐士</p>
  <div class="site-description" itemprop="description">talk is cheap, show me the code</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">347</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">53</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
        <span class="site-state-item-count">115</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">田园隐士</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">587k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">8:53</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  
      

<script>
  if (typeof MathJax === 'undefined') {
    window.MathJax = {
      loader: {
          load: ['[tex]/mhchem'],
        source: {
          '[tex]/amsCd': '[tex]/amscd',
          '[tex]/AMScd': '[tex]/amscd'
        }
      },
      tex: {
        inlineMath: {'[+]': [['$', '$']]},
          packages: {'[+]': ['mhchem']},
        tags: 'ams'
      },
      options: {
        renderActions: {
          findScript: [10, doc => {
            document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
              const display = !!node.type.match(/; *mode=display/);
              const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
              const text = document.createTextNode('');
              node.parentNode.replaceChild(text, node);
              math.start = {node: text, delim: '', n: 0};
              math.end = {node: text, delim: '', n: 0};
              doc.math.push(math);
            });
          }, '', false],
          insertedScript: [200, () => {
            document.querySelectorAll('mjx-container').forEach(node => {
              let target = node.parentNode;
              if (target.nodeName.toLowerCase() === 'li') {
                target.parentNode.classList.add('has-jax');
              }
            });
          }, '', false]
        }
      }
    };
    (function () {
      var script = document.createElement('script');
      script.src = '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
      script.defer = true;
      document.head.appendChild(script);
    })();
  } else {
    MathJax.startup.document.state(0);
    MathJax.texReset();
    MathJax.typeset();
  }
</script>

    

  

</body>
</html>
